#include <gtest/gtest.h>

#include "kiva/parser.h"

namespace kiva {
namespace {

struct ParserTest : ::testing::Test {
  void SetUp() override { parser_ = Parser::New(); }

  void TearDown() override { parser_.reset(); }

  ~ParserTest() override {}

  std::unique_ptr<Parser> parser_;
};

TEST(Parser, ConvertFromNodeTypeToEnum) {
  EXPECT_EQ(Parser::ToOperator(NodeType::kAdd), Parser::Operator::Add);
  EXPECT_EQ(Parser::ToOperator(NodeType::kSub), Parser::Operator::Sub);
  EXPECT_EQ(Parser::ToOperator(NodeType::kMult), Parser::Operator::Mult);
  EXPECT_EQ(Parser::ToOperator(NodeType::kMatMult),
            Parser::Operator::MatMult);
  EXPECT_EQ(Parser::ToOperator(NodeType::kDiv), Parser::Operator::Div);
  EXPECT_EQ(Parser::ToOperator(NodeType::kMod), Parser::Operator::Mod);
  EXPECT_EQ(Parser::ToOperator(NodeType::kPow), Parser::Operator::Pow);
  EXPECT_EQ(Parser::ToOperator(NodeType::kLShift), Parser::Operator::LShift);
  EXPECT_EQ(Parser::ToOperator(NodeType::kRShift), Parser::Operator::RShift);
  EXPECT_EQ(Parser::ToOperator(NodeType::kBitOr), Parser::Operator::BitOr);
  EXPECT_EQ(Parser::ToOperator(NodeType::kBitAnd), Parser::Operator::BitAnd);
  EXPECT_EQ(Parser::ToOperator(NodeType::kBitXor), Parser::Operator::BitXor);
  EXPECT_EQ(Parser::ToOperator(NodeType::kBitAnd), Parser::Operator::BitAnd);
  EXPECT_EQ(Parser::ToOperator(NodeType::kFloorDiv),
            Parser::Operator::FloorDiv);

  EXPECT_EQ(Parser::ToUnaryOperator(NodeType::kInvert),
            Parser::UnaryOperator::Invert);
  EXPECT_EQ(Parser::ToUnaryOperator(NodeType::kNot),
            Parser::UnaryOperator::Not);
  EXPECT_EQ(Parser::ToUnaryOperator(NodeType::kUAdd),
            Parser::UnaryOperator::UAdd);
  EXPECT_EQ(Parser::ToUnaryOperator(NodeType::kUSub),
            Parser::UnaryOperator::USub);

  EXPECT_EQ(Parser::ToBoolOperator(NodeType::kAnd),
            Parser::BoolOperator::And);
  EXPECT_EQ(Parser::ToBoolOperator(NodeType::kOr), Parser::BoolOperator::Or);

#define KIVA_TEST_OP_CONVERT(Name, Op)                    \
  EXPECT_EQ(Parser::ToCompareOperator(NodeType::k##Name), \
            Parser::CompareOperator::Name);

  KIVA_COMPARE_LIST(KIVA_TEST_OP_CONVERT)
}

}  // namespace

}  // namespace kiva
